1 00:00:00,480 --> 00:00:00,720 All right. 2 00:00:00,720 --> 00:00:05,550 So now I'm going to point out something that you may have noticed, may not have, but you will eventually. 3 00:00:05,730 --> 00:00:11,490 If I shoot my other player and the body, we do damage. 4 00:00:11,490 --> 00:00:15,110 If I shoot him in the head, we don't. 5 00:00:15,120 --> 00:00:16,920 Right hand. 6 00:00:17,100 --> 00:00:18,960 Fine foot. 7 00:00:19,320 --> 00:00:21,330 Fine head. 8 00:00:21,330 --> 00:00:23,730 No, that's because of the hair. 9 00:00:24,060 --> 00:00:27,000 There's an accessory and the hair is an accessory. 10 00:00:27,000 --> 00:00:31,110 But we're going to have trouble with, like, backpacks and things like that. 11 00:00:31,110 --> 00:00:34,980 So we're going to have to take care of accessories for our simple pistol. 12 00:00:35,370 --> 00:00:40,740 There are a lot of ways of dealing with accessories when you're making a weapon, but I wanted a way 13 00:00:40,740 --> 00:00:44,550 that's going to work with recast weapons, which we haven't made yet. 14 00:00:45,120 --> 00:00:52,200 Mouse click weapons, which we have one of and I didn't want to get in and change the code in my pistol. 15 00:00:52,200 --> 00:00:53,880 So how do I do that? 16 00:00:53,880 --> 00:00:56,280 I'm going to go to game manager. 17 00:00:57,050 --> 00:00:58,730 I haven't seen a lot of people do this, actually. 18 00:00:58,730 --> 00:01:03,110 I've never seen anybody do this, but I think it's a really good idea and it works. 19 00:01:03,320 --> 00:01:08,030 I'm going to make a function above that player added event. 20 00:01:08,180 --> 00:01:11,510 I'm going to call this exclude 21 00:01:13,640 --> 00:01:18,800 accessory and then I'm going to pass my part in that. 22 00:01:19,640 --> 00:01:21,440 We're going to check to see if it's an accessory. 23 00:01:21,440 --> 00:01:33,830 The part I'm going to say, if part is a accessory, then let's take a look at everything underneath 24 00:01:33,830 --> 00:01:34,790 that part. 25 00:01:34,790 --> 00:01:37,700 Like there's going to be a handle and stuff like that. 26 00:01:37,790 --> 00:01:45,710 Let's say for R and V in pairs part get children 27 00:01:47,540 --> 00:01:48,590 do. 28 00:01:49,850 --> 00:02:01,610 If V is a base part, then so like think of our pistol, right? 29 00:02:01,610 --> 00:02:05,600 Our pistol is a tool which is similar to an accessory. 30 00:02:05,600 --> 00:02:10,390 It's got a handle on it and it's got that gun part, which is a mesh part. 31 00:02:10,400 --> 00:02:14,810 Those parts can block our casting in our clicks. 32 00:02:14,810 --> 00:02:22,340 So all of those parts that can block that are bass parts or some sort of subcategory of bass part, 33 00:02:22,520 --> 00:02:28,540 then what we're going to do is we're going to make sure that can collide is false. 34 00:02:28,550 --> 00:02:31,640 Now handles are they can collide becomes false anyway. 35 00:02:32,120 --> 00:02:38,690 But if can collide is false, then we can turn something called can query as false. 36 00:02:38,690 --> 00:02:46,280 And this is what indicates whether you can query something with a ray cast or a mouse click. 37 00:02:46,280 --> 00:02:51,950 If we make it false, that accessory becomes invisible to our mouse click and our array cast. 38 00:02:52,160 --> 00:02:52,410 All right. 39 00:02:52,430 --> 00:02:54,180 But we're not using the array cast yet. 40 00:02:54,200 --> 00:02:57,950 Now, underneath, underneath this player added, Let's see. 41 00:02:57,950 --> 00:02:58,490 Where is that? 42 00:02:58,490 --> 00:02:59,240 Right here. 43 00:03:00,400 --> 00:03:01,270 Yes. 44 00:03:01,390 --> 00:03:06,460 Let's do a player dot character appearance loaded. 45 00:03:06,460 --> 00:03:08,560 This fires after the character is added. 46 00:03:08,570 --> 00:03:14,590 We want to make sure there's clothes on and stuff and then we're going to connect to an anonymous function. 47 00:03:16,270 --> 00:03:25,390 The char is going to get passed in and we're going to say for I and V in pairs of our char, we're going 48 00:03:25,390 --> 00:03:26,440 to get children. 49 00:03:26,440 --> 00:03:28,390 Accessory is on one level down. 50 00:03:28,390 --> 00:03:35,020 So to get children to work do so the V is the part I as the counter V's are. 51 00:03:35,020 --> 00:03:37,360 The V is the part that's underneath the character. 52 00:03:37,360 --> 00:03:41,350 We're going to do exclude accessory pass in the V. 53 00:03:41,650 --> 00:03:45,910 Now, unfortunately, sometimes all the parts aren't loaded. 54 00:03:45,910 --> 00:03:48,430 This will fire and it'll exclude some parts. 55 00:03:48,430 --> 00:03:57,850 So let's get our char hook up our descendant added event by connecting it to an anonymous function. 56 00:03:57,850 --> 00:04:05,860 The part that got added after where this triggered is going to be one of the arguments. 57 00:04:05,860 --> 00:04:12,220 I'm going to get my exclude accessory and pass that in to just to make sure nothing sneaked pass our 58 00:04:12,220 --> 00:04:14,190 for loop right then we're going to do that. 59 00:04:14,200 --> 00:04:19,230 Now we should be able to fire our our pistol and hit somebody in the head. 60 00:04:19,240 --> 00:04:23,590 Let's go to our test hit the start with two players playing. 61 00:04:23,590 --> 00:04:24,760 I'm going to pause video. 62 00:04:24,850 --> 00:04:25,810 It starts up. 63 00:04:27,690 --> 00:04:29,160 All right, here we go. 64 00:04:29,490 --> 00:04:30,810 Let's try it out. 65 00:04:31,080 --> 00:04:32,840 Wait for my bubble to go away. 66 00:04:32,850 --> 00:04:34,260 His bubble go away. 67 00:04:35,660 --> 00:04:36,200 Boom. 68 00:04:36,200 --> 00:04:36,740 We got them. 69 00:04:36,740 --> 00:04:38,210 We got them ready to pile here. 70 00:04:38,570 --> 00:04:39,830 No problemo. 71 00:04:40,310 --> 00:04:41,870 All right, so we solve that problem. 72 00:04:41,870 --> 00:04:42,980 That's pretty cool.